import { Form, Input, Select, DatePicker, Button, message } from 'antd';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import type { RadioChangeEvent } from 'antd';
import { Radio } from 'antd';
import * as service from '../../../../api/zzachieve';

interface Props { }
function AchieFirstAdd(props: Props) {

    const { RangePicker } = DatePicker;

    const [messageApi, contextHolder] = message.useMessage();

    const { Option } = Select;

    const navigate = useNavigate()

    const onFinish = async (values: any) => {
        console.log('Success:', values);
        // service.people_add(values).then(res => {
        let res = await service.people_moduleadd(values)
        console.log(res.data);
        if (res.status == 201) {
            messageApi.open({
                type: 'success',
                content: '添加成功',
            });
            navigate('/index/achievements/achieForthTwo')
        }
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);


    };
    const [value, setValue] = useState(1);

    const onChange = (e: RadioChangeEvent) => {
        console.log('radio checked', e.target.value);
        setValue(e.target.value);
    };

    return (
        <div className='add'>
            <div className='top'>基础信息</div>
            <Form
                labelCol={{ span: 4 }}
                wrapperCol={{ span: 14 }}
                layout="horizontal"
                style={{ maxWidth: 600 }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
            >
                <Form.Item label="模板名称" name='name' rules={[{ required: true }]}>
                    <Input />
                </Form.Item>
                <Form.Item name="time" label="考核周期" rules={[{ required: true }]}>
                    <Select
                        placeholder=""
                        allowClear
                    >
                        <Option value="月度">月度</Option>
                        <Option value="季度">季度</Option>
                        <Option value="半年度">半年度</Option>
                        <Option value="年度">年度</Option>
                        <Option value="其他">其他</Option>
                    </Select>
                </Form.Item>
                <Form.Item label="method">
                    <Radio.Group onChange={onChange} value={value} >
                        <Radio name="method" value={1}>普通项</Radio>
                        <Radio name="method" value={2}>减分项</Radio>
                        <Radio name="method" value={3}>加分项</Radio>
                    </Radio.Group>
                </Form.Item>
                <Form.Item name="type" label="模板类别" rules={[{ required: true }]}>
                    <Select
                        placeholder=""
                        allowClear
                    >
                        <Option value="销售考核">销售考核</Option>
                        <Option value="设计考核">设计考核</Option>
                        <Option value="客服考核">客服考核</Option>
                        <Option value="产品考核">产品考核</Option>
                        <Option value="测试考核">测试考核</Option>
                        <Option value="研发考核">研发考核</Option>

                    </Select>
                </Form.Item>
                <Form.Item label="备注" name='more'>
                    <Input />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        保存
                    </Button>
                </Form.Item>
            </Form>
            {contextHolder}
        </div>

    );
}
export default AchieFirstAdd;